package top.pmwly;

/**
 * @author Herther
 * @version 1.0.0
 * @ClassName Student.java
 * @Description 学生类
 * @createTime 2021年08月15日 18:22:00
 */

public class Student implements Comparable{

    private String name;
    private Integer age;

    public Student(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 实现ComparableTO 的方法
     * @param o
     * @return
     */
    @Override
    public int compareTo(Object o) {
        Student student = (Student) o;
        //if (this.age < student.getAge()){
        //    return -1;
        //}else if (this.age > student.getAge()){
        //    return 1;
        //}else{
        //    return 0;
        //}
        return this.age - student.getAge();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }


    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
